package com.sicpa.system.service.impl;

import cn.hutool.http.HttpUtil;
import com.sicpa.common.constant.Constants;
import com.sicpa.common.core.redis.RedisCache;
import com.sicpa.common.enums.ConfigKeyEnum;
import com.sicpa.system.service.ISendMobileMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * SendMobileMessageServiceImpl
 * @author lwf
 */
@Service
public class SendMobileMessageServiceImpl implements ISendMobileMessageService {

    private RedisCache redisCache;

    @Autowired
    public SendMobileMessageServiceImpl(RedisCache redisCache) {
        this.redisCache = redisCache;
    }

    /**
     * 短信发送
     * @param content
     * @param mobile
     * @return
     * @throws UnsupportedEncodingException
     */
    @Override
    public String sendMobileMessageGet(String content, String mobile) throws UnsupportedEncodingException {
        Map<String, Object> param = new HashMap<>();
        param.put("CorpID",redisCache.getCacheObject(Constants.SYS_CONFIG_KEY+ConfigKeyEnum.SYS_SHORT_MESSAGE_ACCOUNT.getValue()));
        param.put("Pwd",redisCache.getCacheObject(Constants.SYS_CONFIG_KEY+ConfigKeyEnum.SYS_SHORT_MESSAGE_PWD.getValue()));
        param.put("Content", URLEncoder.encode(redisCache.getCacheObject(Constants.SYS_CONFIG_KEY+ConfigKeyEnum.SYS_SHORT_MESSAGE_PREFIX.getValue())+content,"UTF-8"));
        param.put("Mobile",mobile);
        return HttpUtil.get(redisCache.getCacheObject(Constants.SYS_CONFIG_KEY+ConfigKeyEnum.SYS_SHORT_MESSAGE_INTERFACE.getValue()),param);
    }

}
